<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Jin Tian</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  
  
  
  
  <meta name="description" content="Just My Blog">
<meta property="og:type" content="website">
<meta property="og:title" content="Jin Tian">
<meta property="og:url" content="http://yoursite.com/page/5/index.html">
<meta property="og:site_name" content="Jin Tian">
<meta property="og:description" content="Just My Blog">
<meta property="og:locale" content="zh-CN">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Jin Tian">
<meta name="twitter:description" content="Just My Blog">
  
    <link rel="alternate" href="/atom.xml" title="Jin Tian" type="application/atom+xml">
  

  

  <link rel="icon" href="/css/images/mylogo.jpg">
  <link rel="apple-touch-icon" href="/css/images/mylogo.jpg">
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  <link href="https://fonts.googleapis.com/css?family=Open+Sans|Montserrat:700" rel="stylesheet" type="text/css">
  <link href="https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic" rel="stylesheet" type="text/css">
  <link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">
  <style type="text/css">
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/9749f0/00000000000000000001008f/27/l?subset_id=2&fvd=n5) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/90cf9f/000000000000000000010091/27/l?subset_id=2&fvd=n7) format("woff2");font-weight:500;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/8a5494/000000000000000000013365/27/l?subset_id=2&fvd=n4) format("woff2");font-weight:lighter;font-style:normal;}
    @font-face{font-family:futura-pt;src:url(https://use.typekit.net/af/d337d8/000000000000000000010095/27/l?subset_id=2&fvd=i4) format("woff2");font-weight:400;font-style:italic;}</style>
  <link rel="stylesheet" href="/css/style.css">

  <script src="/js/jquery-3.1.1.min.js"></script>
  <script src="/js/bootstrap.js"></script>

  <!-- Bootstrap core CSS -->
  <link rel="stylesheet" href="/css/bootstrap.css" >

  
    <link rel="stylesheet" href="/css/home.css" >
  

  

  

  
  
  
    <link rel="stylesheet" href="/css/vdonate.css" >
  

</head>



  <body>


  
    <header id="header">

	<!-- 背景图模式 -->
	

    
      <div id="intrologo" class="intro-logo">
    
 


    <canvas width="100%" height="100%"></canvas>
    <script>
      var c = document.getElementsByTagName('canvas')[0],
          x = c.getContext('2d'),
          w = window.innerWidth,
          h = window.innerHeight,
          pr = window.devicePixelRatio || 1,
          f = 90,
          q,
          m = Math,
          r = 0,
          u = m.PI*2,
          v = m.cos,
          z = m.random
      c.width = w*pr
      c.height = h*pr
      x.scale(pr, pr)
      x.globalAlpha = 0.6

      <!-- 折线Polyline背景 -->
      
        function i(){
            x.clearRect(0,0,w,h)
            q=[{x:0,y:h*.7+f},{x:0,y:h*.7-f}]
            while(q[1].x<w+f) d(q[0], q[1])
        }
        function d(i,j){   
            x.beginPath()
            x.moveTo(i.x, i.y)
            x.lineTo(j.x, j.y)
            var k = j.x + (z()*2-0.25)*f,
                n = y(j.y)
            x.lineTo(k, n)
            x.closePath()
            r-=u/-50
            x.fillStyle = '#'+(v(r)*127+128<<16 | v(r+u/3)*127+128<<8 | v(r+u/3*2)*127+128).toString(16)
            x.fill()
            q[0] = q[1]
            q[1] = {x:k,y:n}
        }
        function y(p){
            var t = p + (z()*2-1.1)*f
            return (t>h||t<0) ? y(p) : t
        }
        document.getElementById("intrologo").onclick = i
        document.getElementById("intrologo").ontouchstart = i
        i()

      <!-- 多边形trianglify背景 -->
      
    </script>
    

    
      <div id="homelogo" class="homelogo"> 
    

        
          <div class="homelogoback" >
            <h1><a href="#content" id="logo">Jin Tian</a></h1>
            <h3>Just My Blog</h3>
            <h5>Jintian</h5>
            <!-- <p><a href="https://github.com/iTimeTraveler" target="_blank">Github</a></p> -->
          </div>
        
    
    </div>
  </div>

  <!-- 自适应主页背景大图 -->
  

 <!-- home_logo_image居中 -->
 
    <script>
        var homelogodiv = document.getElementById("homelogo");
        if (document.all.homelogo.offsetWidth > document.body.clientWidth) {
          homelogodiv.style.width = document.body.clientWidth + "px";
          homelogodiv.style.marginLeft = document.body.clientWidth * -0.5 + "px";
        } else {
          homelogodiv.style.width = homelogodiv.clientWidth  + "px";
          homelogodiv.style.marginLeft = (homelogodiv.clientWidth)  * -0.5 + "px";
        }
    </script>
  

  <div class="intro-navigate">
      <p class="navigater-list">
        
          <a id="beautifont" class="main-nav-link" href="/">首页</a>
        
          <a id="beautifont" class="main-nav-link" href="/archives">归档</a>
        
          <a id="beautifont" class="main-nav-link" href="/categories">分类</a>
        
          <a id="beautifont" class="main-nav-link" href="/tags">标签</a>
        
          <a id="beautifont" class="main-nav-link" href="/about">关于</a>
        
          <a id="beautifont" class="main-nav-link" href="http://luoli-luoli.com/chat">chat</a>
        
      </p>
  </div>

</header>
  
  <div id="container">
    <div id="wrap">
      
            
      <div id="content" class="outer">
        
          <section id="main" style="float:none;">
  
    <article id="post-解决树莓派蛋疼的编码问题locale这个屌毛"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/04/06/解决树莓派蛋疼的编码问题locale这个屌毛/">解决树莓派蛋疼的编码问题locale这个屌毛</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/04/06/解决树莓派蛋疼的编码问题locale这个屌毛/" class="article-date">
	  <time datetime="2017-04-06T02:51:00.000Z" itemprop="datePublished">2017-04-06</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Raspberry-Pi-locale-问题"><a href="#Raspberry-Pi-locale-问题" class="headerlink" title="Raspberry Pi locale 问题"></a>Raspberry Pi locale 问题</h2><p>这个问题真鸡巴蛋疼啊，解决方案是首先我的Mac要改一下ssh-config，把senenv这个去掉。最后是改一下树莓派的<code>/etc/locale.gen</code>这个文件，把en_US.UTF-8 注视掉，然后<br><figure class="highlight ebnf"><table><tr><td class="code"><pre><div class="line"><span class="attribute">sudo dpkg-reconfigure locales</span></div></pre></td></tr></table></figure></p>
<p>ok<br>现在就没有那个问题了。</p>
<h2 id="但是问题又来了"><a href="#但是问题又来了" class="headerlink" title="但是问题又来了"></a>但是问题又来了</h2><figure class="highlight groovy"><table><tr><td class="code"><pre><div class="line"><span class="string">dpkg:</span> unrecoverable fatal error, <span class="string">aborting:</span></div><div class="line"> files list file <span class="keyword">for</span> <span class="keyword">package</span> <span class="string">'vim'</span> is missing <span class="keyword">final</span> newline</div><div class="line"><span class="string">E:</span> Sub-process <span class="regexp">/usr/</span>bin/dpkg returned an error code (<span class="number">2</span>)</div></pre></td></tr></table></figure>
<p>树莓派是我打开的方式不对么？各种错卧槽<br>像这种这样的问题，首先就是去到dpkg的info文件夹把这个list的统统删掉，卧槽，然后dpkg configure一下，最后reinstall那个包，应该就可以把这个问题解决掉。</p>
<figure class="highlight crystal"><table><tr><td class="code"><pre><div class="line">sudo rm /var/<span class="class"><span class="keyword">lib</span>/<span class="title">dpkg</span>/<span class="title">info</span>/<span class="title">vim</span>*.<span class="title">list</span></span></div><div class="line">sudo apt install vim --reinstall</div><div class="line">sudo dpkg --configure -a</div><div class="line">sudo apt install vim --reinstall</div></pre></td></tr></table></figure>
<p>记住是这个文件夹： <code>/var/lib/dpkg/info</code></p>

      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-Tensorflow-Series-3-人工智能模仿莎士比亚戏剧以及创作金庸武侠小说"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/04/05/Tensorflow-Series-3-人工智能模仿莎士比亚戏剧以及创作金庸武侠小说/">Tensorflow Series 3 人工智能模仿莎士比亚戏剧以及创作金庸武侠小说</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/04/05/Tensorflow-Series-3-人工智能模仿莎士比亚戏剧以及创作金庸武侠小说/" class="article-date">
	  <time datetime="2017-04-05T06:37:52.000Z" itemprop="datePublished">2017-04-05</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>是的你没有看错，人工智能训练莎士比亚戏剧并模仿创作，还可以创作金庸武侠小说！！<br>
        <!-- 是的你没有看错，人工智能训练莎士比亚戏剧并模仿创作，还可以创作金庸武侠小说！！

本文由牛逼的研究生金天同学原创，欢迎转载，但是请保留这段版权信息，如果你对文章有任何疑问，欢迎微信联系我：jintianiloveu。牛逼大神一一为你解答！

Preface关于中文创作小说的项目在这里，本项目将实现创作莎士比亚戏剧和金庸武侠小说！！！快star！保持更新！！

人工智能模仿莎士比亚戏剧创作这是......  -->
        <p class="article-more-link">
          <a href="/2017/04/05/Tensorflow-Series-3-人工智能模仿莎士比亚戏剧以及创作金庸武侠小说/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-树莓派编译OpenCV，并搭建tensorflow环境跑SSD，就问你怕不怕"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/04/04/树莓派编译OpenCV，并搭建tensorflow环境跑SSD，就问你怕不怕/">树莓派编译OpenCV，并搭建tensorflow环境跑SSD，就问你怕不怕</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/04/04/树莓派编译OpenCV，并搭建tensorflow环境跑SSD，就问你怕不怕/" class="article-date">
	  <time datetime="2017-04-04T10:31:05.000Z" itemprop="datePublished">2017-04-04</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>本文将在我们的树莓派3B+上编译OpenCV！！！并搭建tensorflow环境，跑SSD！！！！<br>
        <!-- 本文将在我们的树莓派3B+上编译OpenCV！！！并搭建tensorflow环境，跑SSD！！！！

你有过想上天的感觉吗？这个教程就是让大家跟我一起上天的。

树莓派3B+编译OpenCV这是第一步也是最重要的一步，没有opencv就无法让树莓派处理图片，视频，我们不仅仅有树莓派，还给树莓派配上了一个摄像头，当然目前还不知道像素咋样，啥也不说先把opencv搞起来。在开搞之前必须要说明一下......  -->
        <p class="article-more-link">
          <a href="/2017/04/04/树莓派编译OpenCV，并搭建tensorflow环境跑SSD，就问你怕不怕/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/深度学习，-树莓派/">深度学习， 树莓派</a></li></ul>

    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-Ubuntu-Mac-之九阴真经"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/03/28/Ubuntu-Mac-之九阴真经/">Ubuntu-Mac 之九阴真经</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/03/28/Ubuntu-Mac-之九阴真经/" class="article-date">
	  <time datetime="2017-03-28T02:48:43.000Z" itemprop="datePublished">2017-03-28</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>为什么不叫做葵花宝典呢？因为我们都是男人，你懂的。<br>
        <!-- 为什么不叫做葵花宝典呢？因为我们都是男人，你懂的。后期慢慢的把ubuntu使用的炸天姿势集中起来，方便后人查阅
Ubuntu下命令行链接wifi这个姿势很重要啊！下面几条命令可以让你在没有登陆图形界面的情况下登陆wifi：首先用这个命令扫描可以使用的wifi：sudo iwlist wlan0 s
wlan0因网卡不同而不同，也可以是eth0，如果你不确定可以按tab建联想。然后用iwcon......  -->
        <p class="article-more-link">
          <a href="/2017/03/28/Ubuntu-Mac-之九阴真经/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-中文自然语言处理Series-1-利用LDA和LSI模型判断两句话是否语义相关"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/03/24/中文自然语言处理Series-1-利用LDA和LSI模型判断两句话是否语义相关/">中文自然语言处理Series 1 利用LDA和LSI模型判断两句话是否语义相关</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/03/24/中文自然语言处理Series-1-利用LDA和LSI模型判断两句话是否语义相关/" class="article-date">
	  <time datetime="2017-03-24T05:55:47.000Z" itemprop="datePublished">2017-03-24</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        
      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-Tensorflow-Series-2-SSD-Detection自动识别出你和你室友"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/03/24/Tensorflow-Series-2-SSD-Detection自动识别出你和你室友/">Tensorflow Series 2 SSD Detection自动识别出你和你室友</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/03/24/Tensorflow-Series-2-SSD-Detection自动识别出你和你室友/" class="article-date">
	  <time datetime="2017-03-24T04:26:28.000Z" itemprop="datePublished">2017-03-24</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>完整的SSD训练自己的数据集思路，不仅可以尝试下标注数据的乐趣，还能作一个人脸自动识别程序！！放在寝室门上和电脑解锁神器！！<br>
        <!-- 完整的SSD训练自己的数据集思路，不仅可以尝试下标注数据的乐趣，还能作一个人脸自动识别程序！！放在寝室门上和电脑解锁神器！！

本文由牛逼的研究生金天同学原创，欢迎转载，但是请保留这段版权信息，如果你对文章有任何疑问，欢迎微信联系我：jintianiloveu。牛逼大神一一为你解答！

Tensorflow Face Identifier – An AI Who Can Recognize ......  -->
        <p class="article-more-link">
          <a href="/2017/03/24/Tensorflow-Series-2-SSD-Detection自动识别出你和你室友/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-Tensorflow-Series-1-使用LSTM实现古诗人工智能作诗"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/03/08/Tensorflow-Series-1-使用LSTM实现古诗人工智能作诗/">Tensorflow Series 1 使用LSTM实现古诗人工智能作诗</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/03/08/Tensorflow-Series-1-使用LSTM实现古诗人工智能作诗/" class="article-date">
	  <time datetime="2017-03-08T07:31:47.000Z" itemprop="datePublished">2017-03-08</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>时隔多年终于实现了这个牛逼的作诗机器人。大家可以看看效果图感受一下<br>
        <!-- 时隔多年终于实现了这个牛逼的作诗机器人。大家可以看看效果图感受一下

本文由清华大学较为牛逼的研究生金天同学原创，欢迎转载，但是请保留这段版权信息，如果你对文章有任何疑问，欢迎微信联系我：jintianiloveu。牛逼大神一一为你解答！

它已经不仅仅能够作古诗，还能模仿周杰伦创作歌词！！这是2017-03-9更新的功能，模仿周杰伦歌曲创作歌词，大家先来感受一下它创作的歌词：
我的你的她蛾......  -->
        <p class="article-more-link">
          <a href="/2017/03/08/Tensorflow-Series-1-使用LSTM实现古诗人工智能作诗/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Tensorflow-人工智能/">Tensorflow 人工智能</a></li></ul>

    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-三行代码Tensorflow入门"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/02/20/三行代码Tensorflow入门/">三行代码Tensorflow入门</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/02/20/三行代码Tensorflow入门/" class="article-date">
	  <time datetime="2017-02-20T08:04:14.000Z" itemprop="datePublished">2017-02-20</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>本教程将用三个函数带你入门tensorflow，如果还没有入门那我也是没有办法了<br>
        <!-- 本教程将用三个函数带你入门tensorflow，如果还没有入门那我也是没有办法了
Tensorflow现状为什么选择tensorflow呢？不是因为它多么多么屌，而是因为它的设计很符合一个神经网络库，比如说什么图啊，数据流啊，咋一听你可能没有感觉，你想一下神经网络不也是这样的吗？至于mxnet，caffe这样的库，学会了tensorflow之后并没有感觉这些库有什么难点，更多是觉得这些库写的......  -->
        <p class="article-more-link">
          <a href="/2017/02/20/三行代码Tensorflow入门/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-云服务器搭建必备教程"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/02/03/云服务器搭建必备教程/">云服务器搭建必备教程</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/02/03/云服务器搭建必备教程/" class="article-date">
	  <time datetime="2017-02-03T02:15:38.000Z" itemprop="datePublished">2017-02-03</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>网站，APP上云必备套路，本文针对ubuntu以及使用nginx和django建站的伙伴们<br>
        <!-- 网站，APP上云必备套路，本文针对ubuntu以及使用nginx和django建站的伙伴们

本文由金天原创，欢迎转载，请保留这段版权信息，enjoy :)

上云自动化脚本这里说的自动化脚本指的是搭建nginx+django+gunicorn+supervisor+postgreslq的脚本，只需要执行：mkdir Deploycd Deploywget https://github.co......  -->
        <p class="article-more-link">
          <a href="/2017/02/03/云服务器搭建必备教程/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-2017-12-22-yolo教程"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/02/02/2017-12-22-yolo教程/">Yolo darknet训练自己的数据集教程(Newest 2016.12.23)</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/02/02/2017-12-22-yolo教程/" class="article-date">
	  <time datetime="2017-02-02T13:31:45.000Z" itemprop="datePublished">2017-02-02</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="Yolo-darknet训练自己的数据集教程-Newest-2016-12-23"><a href="#Yolo-darknet训练自己的数据集教程-Newest-2016-12-23" class="headerlink" title="Yolo darknet训练自己的数据集教程(Newest 2016.12.23)"></a>Yolo darknet训练自己的数据集教程(Newest 2016.12.23)</h2><blockquote>
<p>经过两天的折腾终于搞定了Yolo训练自己的数据集的过程，整个过程其实并不繁琐，只是网上一些过时的教程已经不适用了，依照那个反而让大家各种出出错，加之Yolo中文教程过少，因此本大神再次放一个，如果大家有任何问题直接在文章后面评论即可，笔者看到之后给予第一时间回复。</p>
</blockquote>
<p><strong>先插一句，Atom中文不能跟随窗口wrap文字的同学，打开settingview，设置soft wrap即可，百度上的答案真的是渣</strong></p>
<h3 id="Yolo简介"><a href="#Yolo简介" class="headerlink" title="Yolo简介"></a>Yolo简介</h3><p>在训练数据集之前，相信大家对yolo应该有一些了解，本文所采用的测试环境为：Ubuntu 16.04 + opencv2.4 + cuda8 + cudnn5.1 PLUS GTX1080，当然这个硬件不是必须，在下只是偶尔装一下逼。Yolo基于darknet编写，而编译draknet的时候最好安装一下opencv，因为没有opencv图不会自动弹出，没有那种快感，你懂得，不知道如何安装opencv的同学去我之前写的几个博客中搜寻。均能够找到最新的答案。</p>
<p>yolo之所以快，是因为它的方法和fastrcnn以及其他detect算法不同，而采用了很多ssd的思想，在最新的更新中，yolo也改进了他们的算法，在pascal voc数据集上取得了不错的结果。本文将主要利用yolo来做realtime detect，对自己的数据进行训练和预测。</p>
<h3 id="开始开车"><a href="#开始开车" class="headerlink" title="开始开车"></a>开始开车</h3><p>OK，闲话不多说，让我们直接上车，这次是无人驾驶，速度比较快，大家系好安全带。</p>
<p><strong>Step 1 编译darknet，并熟悉目录结构</strong></p>
<p>第一部分没有什么说的，很简单其实，首先clone代码到本地~目录：<br><figure class="highlight vim"><table><tr><td class="code"><pre><div class="line"><span class="keyword">cd</span> ~</div><div class="line">git clone http<span class="variable">s:</span>//github.<span class="keyword">com</span>/pjreddie/darknet</div><div class="line"><span class="keyword">cd</span> darknet</div><div class="line"><span class="keyword">make</span></div></pre></td></tr></table></figure></p>
<p>这个时候我们在home根目录就有了darknet了。直接编译，不需要修改任何参数，当然如何你是土豪，你有GTX1080,像我一样（手动装比）。可以编译一下Makefile里面的参数。为了防止大家出错我还是说一下，直接改标志为：<br><figure class="highlight ini"><table><tr><td class="code"><pre><div class="line"><span class="attr">GPU</span>=<span class="number">1</span></div><div class="line"><span class="attr">CUDNN</span>=<span class="number">1</span></div><div class="line"><span class="attr">OPENCV</span>=<span class="number">0</span></div><div class="line"><span class="attr">DEBUG</span>=<span class="number">0</span></div></pre></td></tr></table></figure></p>
<p>如果你的cuda没有设置环境变量，nvcc的路径也设置一下：<br><figure class="highlight awk"><table><tr><td class="code"><pre><div class="line">NVCC=<span class="regexp">/usr/</span>local<span class="regexp">/cuda/</span>bin<span class="regexp">/nvcc</span></div></pre></td></tr></table></figure></p>
<p>不要想的很复杂其实很简单。ok，现在直接make，编译就可以了。</p>
<p><strong>Step 2 准备自己的数据集 </strong></p>
<p>好了我们现在有了darktnet，但是我要那个匡出物体的掉炸天的图怎么搞？莫慌，我们先用darknet自带的测试数据来测试一下。<br>首先呢，yolo这个网络是训练VOC数据集得来的，20中物体都能识别出来，我们直接下载已经训练好的权重然后来预测一张图片看看：<br><figure class="highlight awk"><table><tr><td class="code"><pre><div class="line">wget http:<span class="regexp">//</span>pjreddie.com<span class="regexp">/media/</span>files<span class="regexp">/yolo.weights</span></div></pre></td></tr></table></figure></p>
<p>这时候我们就下载好了yolo.weights，在darknet目录下。然后我们就可以用这个权重来预测啦！<br><figure class="highlight stylus"><table><tr><td class="code"><pre><div class="line">./darknet detect cfg/yolo<span class="selector-class">.cfg</span> yolo<span class="selector-class">.weights</span> data/dog.jpg</div></pre></td></tr></table></figure></p>
<p>detect命令意思是，检测，后面还有i一个命令是detector train，后者是训练的命令，预测用detect，cfg/yolo.cfg就是yolo这个网络的结构文件，后面是权重，最后后面是图片。<br>ok，enter你就可以看到狗和自行车了！～<br>这就搞定了darknet，那么问题来了。自己的数据集怎么准备呢？<br>重点来了重点来了：</p>
<ul>
<li>images 准备</li>
</ul>
<p>首先，把你的图片放到一个/images 文件夹下面，文件名的名字要有规律，比如0001.jpg,0002.jpg….0100.jpg;</p>
<ul>
<li>xml 准备</li>
</ul>
<p>我相信很多人都需要用图片标注工具来对图片生成标注信息来训练，但是图片标注工具生成的多半是xml的标签信息。darknet需要的label并不是xml格式，而是一张图片一个txt的形式，txt中是你标注的物体方框坐标。后面我会放出几个脚本来处理。</p>
<ul>
<li>xml 转 darknet label</li>
</ul>
<p>xml转为darknet需要的label形式，一张图片一个标注信息。</p>
<ul>
<li>生成图片路径<br>最后一部我们要生成两个txt文件，一个是train.txt,一个是valid.txt，train.txt包含了你训练图片需要的图片路径，没一行都是一张图片的路径，为了防止出错，后面我放出一个统一的脚本生成这个train.txt。</li>
</ul>
<p><strong>Step 3 训练之前修改darknet参数</strong></p>
<p>接下来就要修改darknet的参数了，只要修改/cfg/voc.data 文件，因为yolo是为了voc而存在的，为了不修改源代码的情况下来训练我们的数据，建议直接修改voc.data而不是修改voc.data文件名。修改内容如下：<br><figure class="highlight ini"><table><tr><td class="code"><pre><div class="line"><span class="attr">classes</span>= <span class="number">20</span></div><div class="line"><span class="attr">train</span>  = /home/pjreddie/data/voc/train.txt</div><div class="line"><span class="attr">valid</span>  = /home/pjreddie/data/voc/<span class="number">2007</span>_test.txt</div><div class="line"><span class="attr">names</span> = data/voc.names</div><div class="line"><span class="attr">backup</span> = /home/pjreddie/backup/</div></pre></td></tr></table></figure></p>
<p>这里，classes就是你数据集的类别，names你的新建一个，在data下面，然后在这里指向它，仿照voc.names 新建即可。<br>修改train.txt valid.txt的路径，用绝对路径哦，防止出错，因为你darknet和数据可能不再一个目录。<br>ok，这就setup完了，接着直接训练。<br>不过训练之前获取一个预处理的权重：<br><figure class="highlight awk"><table><tr><td class="code"><pre><div class="line">curl -O http:<span class="regexp">//</span>pjreddie.com<span class="regexp">/media/</span>files<span class="regexp">/darknet19_448.conv.23</span></div></pre></td></tr></table></figure></p>
<p>然后，train：<br><figure class="highlight stylus"><table><tr><td class="code"><pre><div class="line">./darknet detector train cfg/voc<span class="selector-class">.data</span> cfg/yolo-voc<span class="selector-class">.cfg</span> darknet19_448<span class="selector-class">.conv</span>.<span class="number">23</span></div></pre></td></tr></table></figure></p>
<p>对了，如果你上面改了voc.data的文件名，这里也要改，所以说其实改也是可以的。然后yolo-voc.cfg就可以不改了。</p>
<p><strong>Step 4 yolo训练出的模型预测</strong><br><figure class="highlight stylus"><table><tr><td class="code"><pre><div class="line">./darknet detect cfg/yolo-voc<span class="selector-class">.cfg</span> /backup/voc<span class="selector-class">.weights</span> data/sample.jpg</div></pre></td></tr></table></figure></p>
<p>这里不要和直接copy我的代码，cfg/yolo-voc.cfg就是我们训练的网络。后面是训练保存的权重，最后是你要预测的图片。<br>OK，看看结果咋么样～</p>

      
    </div>
    <footer class="article-footer">
      
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/深度学习/">深度学习</a></li></ul>

    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-解决任何locale语言不对的问题"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/02/02/解决任何locale语言不对的问题/">解决任何locale语言不对的问题</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/02/02/解决任何locale语言不对的问题/" class="article-date">
	  <time datetime="2017-02-02T13:18:42.000Z" itemprop="datePublished">2017-02-02</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <p>专治各种locale引起的疑难杂症，药到病除，罕见良方<br>
        <!-- 专治各种locale引起的疑难杂症，药到病除，罕见良方
locale引起的各种蛋疼错误
在pip安装时有时候会有local设置不对的错误
在数据库时有时候会有编码错误

这背后的罪魁祸首都是locale这个文件设置不正确，在/etc/default/locale这里是locale的配置文件，直接修改它：
LC_CTYPE="en_US.UTF-8"LC_ALL="en_US.UTF-8"LA......  -->
        <p class="article-more-link">
          <a href="/2017/02/02/解决任何locale语言不对的问题/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-Django-6-Django-nginx-gunicorn-搭建web生产环境教程"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/02/02/Django-6-Django-nginx-gunicorn-搭建web生产环境教程/">Django 6 Django，nginx，gunicorn搭建web生产环境教程</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/02/02/Django-6-Django-nginx-gunicorn-搭建web生产环境教程/" class="article-date">
	  <time datetime="2017-02-02T05:04:22.000Z" itemprop="datePublished">2017-02-02</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <blockquote>
<p>Django和nginx以及gunicorn搭建生产web环境教程。<br>
        <!-- 
Django和nginx以及gunicorn搭建生产web环境教程。
本文由作者金天原创，欢迎大家转载，不过请保留这段版权信息，多谢合作，如对本文有任何问题欢迎联系作者: jintianiloveu。

前言依旧在动笔之前说一句，这个着实有点蛋疼啊，当然如果你有过搭建服务器经验的可以忽略，第一次搞主要是卡在gunicorn以及nginx上，当然还有supervisor这个附角色。我简单的捋......  -->
        <p class="article-more-link">
          <a href="/2017/02/02/Django-6-Django-nginx-gunicorn-搭建web生产环境教程/#more">阅读全文</a>
        </p>
      
    </div>
    <footer class="article-footer">
      
      
      
    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-2017-1-6-Caffe-训练自己的数据集并用Python接口预测和批量预测"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/02/02/2017-1-6-Caffe-训练自己的数据集并用Python接口预测和批量预测/">Caffe训练自己的数据集并用Python接口预测</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/02/02/2017-1-6-Caffe-训练自己的数据集并用Python接口预测和批量预测/" class="article-date">
	  <time datetime="2017-02-01T18:31:45.000Z" itemprop="datePublished">2017-02-02</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Caffe训练自己的数据集并用Python接口预测"><a href="#Caffe训练自己的数据集并用Python接口预测" class="headerlink" title="Caffe训练自己的数据集并用Python接口预测"></a>Caffe训练自己的数据集并用Python接口预测</h3><blockquote>
<p>本教程作者是在读硕士金天童鞋，在当地较为英俊的男子，大家对教程有任何疑问欢迎联系我：WeChat<br><code>jintianiloveu</code>，同时也欢迎大家转载评论，不过请保留这段版权信息，桑口～</p>
</blockquote>
<h4 id="Caffe安装"><a href="#Caffe安装" class="headerlink" title="Caffe安装"></a>Caffe安装</h4><p>首先还是简要的说一下Caffe在Ubuntu下的安装过程，具体安装过程如下：</p>
<ul>
<li><strong>安装前置依赖</strong><br>前置依赖项较多，好在Ubuntu下都可以通过apt下载安装，这个命令一阵复制粘帖吧：<figure class="highlight q"><table><tr><td class="code"><pre><div class="line">sudo apt-<span class="built_in">get</span> upgrade</div><div class="line">sudo apt-<span class="built_in">get</span> install -y build-essential cmake git pkg-config</div><div class="line">sudo apt-<span class="built_in">get</span> install -y libprotobuf-<span class="built_in">dev</span> libleveldb-<span class="built_in">dev</span> libsnappy-<span class="built_in">dev</span> libhdf5-serial-<span class="built_in">dev</span> protobuf-compiler</div><div class="line">sudo apt-<span class="built_in">get</span> install -y libatlas-base-<span class="built_in">dev</span></div><div class="line">sudo apt-<span class="built_in">get</span> install -y --no-install-recommends libboost-<span class="built_in">all</span>-<span class="built_in">dev</span></div><div class="line">sudo apt-<span class="built_in">get</span> install -y libgflags-<span class="built_in">dev</span> libgoogle-glog-<span class="built_in">dev</span> liblmdb-<span class="built_in">dev</span></div></pre></td></tr></table></figure>
</li>
</ul>
<p>然后安装OpenCV3.1,这个安装已经轻车熟路了。大家对此有和疑问的查看我这个<a href="www.lewisjin.coding.me">博客</a>，找到Ubuntu下安装OpenCV的教程进行安装。<br>接下来就简单了，不过为了防止后面导入caffe出问题，建议软链接一下这个东西：<br><figure class="highlight crystal"><table><tr><td class="code"><pre><div class="line">sudo ln -s /usr/<span class="class"><span class="keyword">lib</span>/<span class="title">x86_64</span>-<span class="title">linux</span>-<span class="title">gnu</span>/<span class="title">libboost_python</span>-<span class="title">py35</span>.<span class="title">so</span> /<span class="title">usr</span>/<span class="title">lib</span>/<span class="title">x86_64</span>-<span class="title">linux</span>-<span class="title">gnu</span>/<span class="title">libboost_python3</span>.<span class="title">so</span></span></div></pre></td></tr></table></figure></p>
<p>接着clone项目：<br><figure class="highlight crmsh"><table><tr><td class="code"><pre><div class="line">git <span class="keyword">clone</span> <span class="title">https</span>://github.com/BVLC/caffe.git</div></pre></td></tr></table></figure></p>
<p>然后在我的<a href="http://github.com/jinfagang/UbuntuScripts.git" target="_blank" rel="noopener">Repo</a>里面下载<code>Makefile</code>和<code>Makefile.config</code>来替换原有的。接着就是安装python依赖，这里不要按照其他教程里面的安装官方的caffe/python下的requirement.txt，instead，下载我的，然后运行：<br><figure class="highlight sql"><table><tr><td class="code"><pre><div class="line">sudo pip3 <span class="keyword">install</span> <span class="comment">--upgrade -r python/requirements_python3.txt</span></div></pre></td></tr></table></figure></p>
<p>后面的<code>requirements_python3.txt</code>也可以从上面的Repo下载。<br>接着直接安装就行了：<br><figure class="highlight vim"><table><tr><td class="code"><pre><div class="line"><span class="keyword">make</span> <span class="keyword">all</span> -<span class="keyword">j</span></div><div class="line"><span class="keyword">make</span> pycaffe</div></pre></td></tr></table></figure></p>
<p>测试一下是否安装成功：<br><figure class="highlight stylus"><table><tr><td class="code"><pre><div class="line">./data/mnist/get_mnist<span class="selector-class">.sh</span></div><div class="line">./examples/mnist/create_mnist<span class="selector-class">.sh</span></div><div class="line">./examples/mnist/train_lenet.sh</div></pre></td></tr></table></figure></p>
<p>如果成功你就会看到caffe在训练mnist了，大概几千次之后准确度就可以达到99%，非常好。</p>
<h4 id="Caffe生成并训练自己的数据集"><a href="#Caffe生成并训练自己的数据集" class="headerlink" title="Caffe生成并训练自己的数据集"></a>Caffe生成并训练自己的数据集</h4><p>本教程所有的代码，文件目录结构可以在我的github上下载，<a href="https://github.com/jinfagang/caffe_tiny5.git" target="_blank" rel="noopener">点这里</a>,下载之后你会看到一个完整的caffe训练架构，但是数据还得另外下载，我在这里只是上传了5类图片的样张图片，真正的数据集大概有600张的样子。下载地址为<a href="http://pan.baidu.com/s/1milroSS" target="_blank" rel="noopener">这里</a>。<br>接下来要生成caffe需要的数据了，步骤如下，大家先不要方，生成数据是整个过程最复杂的部分，不过这个部分也不是很麻烦，我精简一下步骤：</p>
<p><strong>Step 1</strong> Generate the image name file</p>
<p>Run caffe_path_gen.py in your terminal, just type:<br><figure class="highlight awk"><table><tr><td class="code"><pre><div class="line">python3 caffe_path_gen.py -train=<span class="regexp">/home/</span>jfg<span class="regexp">/caffe_tiny5/</span>tiny5<span class="regexp">/train -shuffle=True</span></div></pre></td></tr></table></figure></p>
<p>-shuffle is optional, because caffe can do this too.<br>In this tutorial we only have train data in image_data folder, we don’t have test image, so we just generate the train image path, and manully divide them into train and test. But if you have test data folder, you also can type:<br><figure class="highlight awk"><table><tr><td class="code"><pre><div class="line">python3 caffe_path_gen.py -train=<span class="regexp">/home/</span>jfg<span class="regexp">/Documents/</span>PythonSpace<span class="regexp">/caffe_tiny5/</span>tiny5<span class="regexp">/train -test=/</span>home<span class="regexp">/jfg/</span>Documents<span class="regexp">/PythonSpace/</span>caffe_tiny5<span class="regexp">/tiny5/</span>test -valid=<span class="regexp">/home/</span>jfg<span class="regexp">/Documents/</span>PythonSpace<span class="regexp">/caffe_tiny5/</span>tiny5<span class="regexp">/valid</span></div></pre></td></tr></table></figure></p>
<p>the valid data only generate image path without labels.<br>After this, you gonna have <strong>train.txt</strong>, <strong>words.txt</strong>.</p>
<p><strong>Step 2</strong> Split train.txt into to train.txt and test.txt</p>
<p><strong>Before split please remove the path just make it like this:</strong><br><figure class="highlight lsl"><table><tr><td class="code"><pre><div class="line">/flower/<span class="number">683.</span>jpg <span class="number">3</span></div><div class="line">/bus/<span class="number">334.</span>jpg <span class="number">0</span></div><div class="line">/bus/<span class="number">336.</span>jpg <span class="number">0</span></div><div class="line">/dinosaur/<span class="number">481.</span>jpg <span class="number">2</span></div><div class="line">/dinosaur/<span class="number">436.</span>jpg <span class="number">2</span></div><div class="line">/bus/<span class="number">327.</span>jpg <span class="number">0</span></div><div class="line">/elephant/<span class="number">595.</span>jpg <span class="number">4</span></div><div class="line">/bus/<span class="number">357.</span>jpg <span class="number">0</span></div><div class="line">/bus/<span class="number">393.</span>jpg <span class="number">0</span></div><div class="line">/bus/<span class="number">375.</span>jpg <span class="number">0</span></div><div class="line">/dinosaur/<span class="number">453.</span>jpg <span class="number">2</span></div><div class="line">/flower/<span class="number">654.</span>jpg <span class="number">3</span></div><div class="line">/dinosaur/<span class="number">491.</span>jpg <span class="number">2</span></div><div class="line">/bus/<span class="number">365.</span>jpg <span class="number">0</span></div><div class="line">/flower/<span class="number">636.</span>jpg <span class="number">3</span></div><div class="line">/flower/<span class="number">629.</span>jpg <span class="number">3</span></div><div class="line">/bus/<span class="number">347.</span>jpg <span class="number">0</span></div><div class="line">/bus/<span class="number">398.</span>jpg <span class="number">0</span></div><div class="line">/horse/<span class="number">761.</span>jpg <span class="number">1</span></div><div class="line">/elephant/<span class="number">560.</span>jpg <span class="number">4</span></div><div class="line">/dinosaur/<span class="number">449.</span>jpg <span class="number">2</span></div><div class="line">/elephant/<span class="number">531.</span>jpg <span class="number">4</span></div><div class="line">/horse/<span class="number">794.</span>jpg <span class="number">1</span></div><div class="line">/horse/<span class="number">743.</span>jpg <span class="number">1</span></div><div class="line">/elephant/<span class="number">586.</span>jpg <span class="number">4</span></div></pre></td></tr></table></figure></p>
<p>But stay with the class prefix</p>
<p><strong>Step 3</strong> Generate Caffe LMDB data file<br>First mkdir a <code>data</code> folder just inside the project directory, and place train.txt and test.txt into it.<br>And then open caffe_create_lmdb.sh and just edit the following two lines:<br><figure class="highlight groovy"><table><tr><td class="code"><pre><div class="line">TRAIN_DATA_ROOT=<span class="regexp">/home/</span>jfg<span class="regexp">/Documents/</span>PythonSpace<span class="regexp">/caffe_tiny5/</span>tiny5/train</div><div class="line">VAL_DATA_ROOT=<span class="regexp">/home/</span>jfg<span class="regexp">/Documents/</span>PythonSpace<span class="regexp">/caffe_tiny5/</span>tiny5/valid</div></pre></td></tr></table></figure></p>
<p>在这一步中，确保TRAIN_DATA_ROOT和上面的train.txt中的文件名能够组成完整的路径即可。</p>
<p><strong>Simply edit two lines, leave other along.</strong><br>Then type:<br><figure class="highlight armasm"><table><tr><td class="code"><pre><div class="line"><span class="keyword">bash </span>caffe_create_lmdb.sh</div></pre></td></tr></table></figure></p>
<p>Tip: Anything wrong, check you mkdir a data folder, and have train.txt and test.txt in it.<br>OK, after this, you gonna have two new folder in your data folder, that is:<br><code>caffe_train_lmdb</code><br><code>caffe_val_lmdb</code><br>this is what we need to feed into caffe net and it is nothing with your original image anymore! It’s complete and clean! Do not warry about path wrong anymore! Very nice!</p>
<p><strong>Step 4</strong> Generate Mean Binary File<br>This step is very easy, don’t change anything ,just type this in your terminal:<br><figure class="highlight armasm"><table><tr><td class="code"><pre><div class="line"><span class="keyword">bash </span>caffe_make_mean.sh</div></pre></td></tr></table></figure></p>
<p>And you gonna have <code>caffe_mean.binaryproto</code> file in your data folder.</p>
<h4 id="开始Caffe训练"><a href="#开始Caffe训练" class="headerlink" title="开始Caffe训练"></a>开始Caffe训练</h4><p>you already have your data, just finish 80% work. 20% to go. Next, we gonna using solver folder. In this folder we have a solver.prototxt and a train_test.prototxt.<br>solver.prototxt is the net pramas setting file.<br>train_test.prototxt is the net structure setting file and your lmdb data feed into net in here.<br><figure class="highlight dts"><table><tr><td class="code"><pre><div class="line"><span class="class">layer </span>&#123;</div><div class="line"><span class="symbol">  name:</span> <span class="string">"cifar"</span></div><div class="line"><span class="symbol">  type:</span> <span class="string">"Data"</span></div><div class="line"><span class="symbol">  top:</span> <span class="string">"data"</span></div><div class="line"><span class="symbol">  top:</span> <span class="string">"label"</span></div><div class="line">  <span class="class">include </span>&#123;</div><div class="line"><span class="symbol">    phase:</span> TRAIN</div><div class="line">  &#125;</div><div class="line">  <span class="class">transform_param </span>&#123;</div><div class="line"><span class="symbol">    mean_file:</span> <span class="string">"/home/jfg/caffe_tiny5/data/caffe_mean.binaryproto"</span></div><div class="line">  &#125;</div><div class="line">  <span class="class">data_param </span>&#123;</div><div class="line"><span class="symbol">    source:</span> <span class="string">"/home/jfg/caffe_tiny5/data/caffe_train_lmdb"</span></div><div class="line"><span class="symbol">    batch_size:</span> <span class="number">100</span></div><div class="line"><span class="symbol">    backend:</span> LMDB</div><div class="line">  &#125;</div><div class="line">&#125;</div><div class="line"><span class="class">layer </span>&#123;</div><div class="line"><span class="symbol">  name:</span> <span class="string">"cifar"</span></div><div class="line"><span class="symbol">  type:</span> <span class="string">"Data"</span></div><div class="line"><span class="symbol">  top:</span> <span class="string">"data"</span></div><div class="line"><span class="symbol">  top:</span> <span class="string">"label"</span></div><div class="line">  <span class="class">include </span>&#123;</div><div class="line"><span class="symbol">    phase:</span> TEST</div><div class="line">  &#125;</div><div class="line">  <span class="class">transform_param </span>&#123;</div><div class="line"><span class="symbol">    mean_file:</span> <span class="string">"/home/jfg/caffe_tiny5/data/caffe_mean.binaryproto"</span></div><div class="line">  &#125;</div><div class="line">  <span class="class">data_param </span>&#123;</div><div class="line"><span class="symbol">    source:</span> <span class="string">"/home/jfg/caffe_tiny5/data/caffe_val_lmdb"</span></div><div class="line"><span class="symbol">    batch_size:</span> <span class="number">100</span></div><div class="line"><span class="symbol">    backend:</span> LMDB</div><div class="line">  &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure></p>
<p>This 2 layer is data feed layer, so you have to change your data path in here.Make sure it correct.<br>Open solver.prototxt, find this 2 and edit it:<br><figure class="highlight avrasm"><table><tr><td class="code"><pre><div class="line"><span class="symbol">net:</span> <span class="string">"/home/jfg/caffe_tiny5/solver/caffenet_train_valid.prototxt"</span></div><div class="line"><span class="symbol">snapshot_prefix:</span> <span class="string">"/home/jfg/caffe_tiny5/model/caffenet"</span></div></pre></td></tr></table></figure></p>
<p>net: it is your train_test.prototxt file postion, snapshot_prefix is your save model path and prefix name, we place all saved models into a model_snapshot folder with prefix cifar10.</p>
<h4 id="训练"><a href="#训练" class="headerlink" title="训练"></a>训练</h4><p>只需要一行命令：<br><figure class="highlight armasm"><table><tr><td class="code"><pre><div class="line"><span class="keyword">bash </span>train_caffe.sh</div></pre></td></tr></table></figure></p>
<h4 id="重点来了，得到模型之后怎么预测"><a href="#重点来了，得到模型之后怎么预测" class="headerlink" title="重点来了，得到模型之后怎么预测"></a>重点来了，得到模型之后怎么预测</h4><p>这里我们使用python接口，直接上代码吧，实际上该的地方也不多：<br><figure class="highlight python"><table><tr><td class="code"><pre><div class="line"><span class="comment"># !/usr/bin/env python</span></div><div class="line"><span class="comment"># -*- coding: utf-8 -*-</span></div><div class="line"><span class="string">"""</span></div><div class="line">caffe_test.py</div><div class="line">http://www.lewisjin.coding.me</div><div class="line">~~~~~~~~~~~~~~~</div><div class="line">This script implement by Jin Fagang.</div><div class="line">: copyright: (c) 2017 Didi-Chuxing.</div><div class="line">: license: Apache2.0, see LICENSE for more details.</div><div class="line">"""</div><div class="line"><span class="keyword">import</span> numpy <span class="keyword">as</span> np</div><div class="line"><span class="keyword">import</span> sys</div><div class="line"><span class="keyword">import</span> os</div><div class="line"><span class="keyword">import</span> cv2</div><div class="line"></div><div class="line">caffe_root = <span class="string">'/home/jfg/caffe/'</span></div><div class="line">sys.path.insert(<span class="number">0</span>, caffe_root + <span class="string">'python'</span>)</div><div class="line"><span class="keyword">import</span> caffe</div><div class="line"></div><div class="line"></div><div class="line">net_file = <span class="string">'/home/jfg/Documents/PythonSpace/caffe_tiny5/solver/caffenet_deploy.prototxt'</span></div><div class="line">caffe_model = <span class="string">'/home/jfg/Documents/PythonSpace/caffe_tiny5/solver/model/caffenet_iter_4500.caffemodel'</span></div><div class="line">mean_file = <span class="string">'/home/jfg/Documents/PythonSpace/caffe_tiny5/data/caffe_mean.binaryproto'</span></div><div class="line">print(<span class="string">'Params loaded!'</span>)</div><div class="line"></div><div class="line">caffe.set_mode_gpu()</div><div class="line">net = caffe.Net(net_file,</div><div class="line">                caffe_model,</div><div class="line">                caffe.TEST)</div><div class="line"></div><div class="line">mean_blob = caffe.proto.caffe_pb2.BlobProto()</div><div class="line">mean_blob.ParseFromString(open(mean_file, <span class="string">'rb'</span>).read())</div><div class="line">mean_npy = caffe.io.blobproto_to_array(mean_blob)</div><div class="line">a = mean_npy[<span class="number">0</span>, :, <span class="number">0</span>, <span class="number">0</span>]</div><div class="line"></div><div class="line">print(net.blobs[<span class="string">'data'</span>].data.shape)</div><div class="line">transformer = caffe.io.Transformer(&#123;<span class="string">'data'</span>: net.blobs[<span class="string">'data'</span>].data.shape&#125;)</div><div class="line">transformer.set_transpose(<span class="string">'data'</span>, (<span class="number">2</span>, <span class="number">0</span>, <span class="number">1</span>))</div><div class="line"></div><div class="line">transformer.set_mean(<span class="string">'data'</span>, a)</div><div class="line">transformer.set_raw_scale(<span class="string">'data'</span>, <span class="number">255.0</span>)</div><div class="line">transformer.set_channel_swap(<span class="string">'data'</span>, (<span class="number">2</span>, <span class="number">1</span>, <span class="number">0</span>))</div><div class="line"></div><div class="line">test_img = <span class="string">'elephant.jpeg'</span></div><div class="line">im = caffe.io.load_image(test_img)</div><div class="line">net.blobs[<span class="string">'data'</span>].data[...] = transformer.preprocess(<span class="string">'data'</span>, im)</div><div class="line"></div><div class="line">predict = net.forward()</div><div class="line">names = []</div><div class="line"><span class="keyword">with</span> open(<span class="string">'words.txt'</span>, <span class="string">'r+'</span>) <span class="keyword">as</span> f:</div><div class="line">    <span class="keyword">for</span> l <span class="keyword">in</span> f.readlines():</div><div class="line">        names.append(l.split(<span class="string">' '</span>)[<span class="number">1</span>].strip())</div><div class="line"></div><div class="line">print(names)</div><div class="line">prob = net.blobs[<span class="string">'prob'</span>].data[<span class="number">0</span>].flatten()</div><div class="line">print(<span class="string">'prob: '</span>, prob)</div><div class="line">print(<span class="string">'class: '</span>, names[np.argmax(prob)])</div><div class="line"></div><div class="line">img = cv2.imread(test_img)</div><div class="line">cv2.imshow(<span class="string">'Image'</span>, img)</div><div class="line">cv2.waitKey(<span class="number">0</span>)</div></pre></td></tr></table></figure></p>
<p>OK，本教程到此结束，欢迎乘坐本次老司机列车。这几天一直没有更新博客不是没有写，而且写了没有上传，还是得发时间整理整理，笔耕不啜才是一代文豪应该做的事情啊。</p>
<h4 id="近期计划"><a href="#近期计划" class="headerlink" title="近期计划"></a>近期计划</h4><p>这是一个花絮，最近我还是决定干点事情了，接下来我会研究一下如何用目标检测算法来识别交通信号灯，这个在无人驾驶领域是肯定会遇到的一个问题，具体来说它有几个难点：</p>
<ul>
<li>检测信号灯的位置</li>
</ul>
<p>要检测信号灯就需要训练图片，标注信号灯的方框，这个好办，现有的网络可以做到很好，接下来有个问题就是第二个点。</p>
<ul>
<li>检测信号等每个路口转向的信号等情况</li>
</ul>
<p>比如我检测到了信号灯，但是这个信号灯是左转通行还是右转通行呢？是左转通行直行禁止右转禁止还是其他情况呢？而且我检测算法可能在一个视角中检测多个红绿灯，但是我真正感兴趣的只是我前方的红绿灯，那么如何来却分识别出来的红绿灯也是个问题。</p>
<p>这两个问题如何解决还得看数据标注的情况。</p>

      
    </div>
    <footer class="article-footer">
      
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/深度学习/">深度学习</a></li></ul>

    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-2017-1-17-Shell编程从入门到放弃系列"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/02/01/2017-1-17-Shell编程从入门到放弃系列/">Shell program from newbie to give up series</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/02/01/2017-1-17-Shell编程从入门到放弃系列/" class="article-date">
	  <time datetime="2017-02-01T12:31:45.000Z" itemprop="datePublished">2017-02-01</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <h3 id="Shell-program-from-newbie-to-give-up-series"><a href="#Shell-program-from-newbie-to-give-up-series" class="headerlink" title="Shell program from newbie to give up series"></a>Shell program from newbie to give up series</h3><blockquote>
<p>This is a tutorial about <strong>shell program</strong>, powerful and faster your work on anywhere, so learn it hard, once you handler it, you can become a geek. If you have any question about this post, you can contact me via wechat: <code>jintianiloveu</code> , if you repost please stay with this copyright annoncement, enjoy :)</p>
</blockquote>
<h3 id="Chapter-1-File-Related"><a href="#Chapter-1-File-Related" class="headerlink" title="Chapter 1 File Related"></a>Chapter 1 File Related</h3><p>ok, in this chapter, the most important and you maybe face with most is file process, such as walk an directory or get all file names in a folder etc. Here I am going write down some useful shell commonds that will hopefully faster your work, even <strong>every faster ever than you think</strong>.</p>
<ul>
<li><strong>get all files and directories</strong><br>Here is one single script:<figure class="highlight bash"><table><tr><td class="code"><pre><div class="line"><span class="comment"># !/bin/bash</span></div><div class="line"><span class="keyword">for</span> file <span class="keyword">in</span> ~/home/data</div><div class="line"><span class="keyword">do</span></div><div class="line">    <span class="built_in">echo</span> <span class="variable">$&#123;file&#125;</span></div><div class="line"><span class="keyword">done</span></div></pre></td></tr></table></figure>
</li>
</ul>
<p>That’s it, you can access every file in a directory, if you want get both file and dirs, try this:<br><figure class="highlight bash"><table><tr><td class="code"><pre><div class="line">all=`ls ~/home/data`</div><div class="line"><span class="keyword">for</span> f <span class="keyword">in</span> all</div><div class="line"><span class="keyword">do</span></div><div class="line">    <span class="keyword">if</span> [ <span class="_">-d</span> <span class="variable">$f</span> ]; <span class="keyword">then</span></div><div class="line">        <span class="built_in">echo</span> <span class="variable">$&#123;f&#125;</span><span class="string">" is a directory"</span></div><div class="line">    <span class="keyword">else</span></div><div class="line">        <span class="built_in">echo</span> <span class="variable">$&#123;f&#125;</span><span class="string">" is a file"</span></div><div class="line">    <span class="keyword">fi</span></div></pre></td></tr></table></figure></p>
<ul>
<li><p><strong>file names and path related</strong><br>Most of the time we are annoying with file names and path, sometimes we want get the file name and another time we want the path. So here you cant use 2 powerful commod to solve all problems. They are <strong>basename</strong> and <strong>dirname</strong>. Look this example:</p>
<figure class="highlight"><table><tr><td class="code"><pre><div class="line"></div><div class="line"></div></pre></td></tr></table></figure>
</li>
<li><p><strong>cycle all names under an (or 2) folder</strong><br>This is a very instresting question. <code>for item in ..</code> this style is very usefule but we can’t cycle 2 items at the same time, indeed we will have this inquirement sometimes. Here I am going solver this using an example:<br>concate 2 folder’s file names into a txt file, say, folder1 have 1.jpg 2.jpg …, and folder2 have 1.txt 2.txt 3.txt…<br>we gonna generate a txt file like this:</p>
<figure class="highlight stylus"><table><tr><td class="code"><pre><div class="line"><span class="number">1</span><span class="selector-class">.jpg</span> <span class="number">1</span><span class="selector-class">.txt</span></div><div class="line"><span class="number">2</span><span class="selector-class">.jpg</span> <span class="number">2</span><span class="selector-class">.txt</span></div><div class="line">...</div></pre></td></tr></table></figure>
</li>
</ul>
<p>abviously, we have to cycle 2 elements at same time. <strong>But! For now we have no method to cycle 2 items in for..in..</strong> So we have to change our plan:<br>We can store the <code>ls |grep &#39;^-&#39;</code> out put into array or list, so we can get them in one for cycle. Here is the script:<br><figure class="highlight bash"><table><tr><td class="code"><pre><div class="line">j=0</div><div class="line"><span class="keyword">for</span> img <span class="keyword">in</span> `ls <span class="variable">$&#123;data_root_dir&#125;</span>/Images|sort -h`</div><div class="line"><span class="keyword">do</span></div><div class="line">    img_list[<span class="variable">$&#123;j&#125;</span>]=<span class="variable">$&#123;img&#125;</span></div><div class="line">    ((j++))</div><div class="line"><span class="keyword">done</span></div><div class="line"></div><div class="line">k=0</div><div class="line"><span class="keyword">for</span> label <span class="keyword">in</span> `ls <span class="variable">$&#123;data_root_dir&#125;</span>/Labels|sort -h`</div><div class="line"><span class="keyword">do</span></div><div class="line">    label_list[<span class="variable">$&#123;k&#125;</span>]=<span class="variable">$&#123;label&#125;</span></div><div class="line">    ((k++))</div><div class="line"><span class="keyword">done</span></div><div class="line"><span class="built_in">echo</span> <span class="variable">$&#123;img_list[0]&#125;</span></div><div class="line"><span class="built_in">echo</span> <span class="variable">$&#123;label_list[0]&#125;</span></div><div class="line"></div><div class="line"><span class="keyword">for</span> ((i=1;i&lt;=<span class="variable">$&#123;#img_list[@]&#125;</span>;i++))</div><div class="line"><span class="keyword">do</span></div><div class="line">    <span class="built_in">echo</span> <span class="variable">$i</span></div><div class="line">    left=<span class="variable">$&#123;img_list[i]&#125;</span></div><div class="line">    right=<span class="variable">$&#123;label_list[i]&#125;</span></div><div class="line">    <span class="built_in">echo</span> <span class="variable">$&#123;left&#125;</span><span class="string">" "</span><span class="variable">$&#123;right&#125;</span></div><div class="line"><span class="keyword">done</span></div></pre></td></tr></table></figure></p>
<p>This code is a little dumped, but I think you can quite get what this means.</p>
<h3 id="Chapter-2-About-txt-file-process"><a href="#Chapter-2-About-txt-file-process" class="headerlink" title="Chapter 2 About txt file process"></a>Chapter 2 About txt file process</h3><p>txt file is the most simple and wide-use file format, handler how to operate them will gaintly faster your work, and make you seems like a god!</p>
<ul>
<li><strong>Witre lines into txt file</strong><br>This is the most basic part of all jobs, and still, the most important. This 2 commond you must <strong>remember into your heart</strong>:<figure class="highlight haskell"><table><tr><td class="code"><pre><div class="line"><span class="title">echo</span> <span class="string">"Hello, world."</span> &gt; ~/<span class="class"><span class="keyword">data</span>/test.txt</span></div><div class="line"><span class="title">echo</span> <span class="string">"Hello, world."</span> &gt;&gt; ~/<span class="class"><span class="keyword">data</span>/test.txt</span></div><div class="line">&gt;: ~/<span class="class"><span class="keyword">data</span>/test.txt</span></div></pre></td></tr></table></figure>
</li>
</ul>
<p>first line: overwrite a string into a file<br>second line: add a line into a file<br>last line: truncate all content in a text file<br>Above is all the basic commond you <strong>have to handler</strong>, is simple yet powerful!</p>
<ul>
<li><strong>Generate a random array</strong><br>ok, another useful general commond that you maybe use all the time, but I think this is not the most simplest way to do this, the purpose is generate a random int array, so that use this we can shuffle txt lines or other things, here is the script:<figure class="highlight bash"><table><tr><td class="code"><pre><div class="line">length_imgs=570</div><div class="line">arr=(`seq <span class="variable">$&#123;length_imgs&#125;</span>`)</div><div class="line"><span class="keyword">for</span> ((i=0;i&lt;10000;i++))</div><div class="line"><span class="keyword">do</span></div><div class="line">        <span class="built_in">let</span> <span class="string">"a=<span class="variable">$RANDOM</span>%<span class="variable">$&#123;length_imgs&#125;</span>"</span></div><div class="line">        <span class="built_in">let</span> <span class="string">"b=<span class="variable">$RANDOM</span>%<span class="variable">$&#123;length_imgs&#125;</span>"</span></div><div class="line">        tmp=<span class="variable">$&#123;arr[$a]&#125;</span></div><div class="line">        arr[<span class="variable">$a</span>]=<span class="variable">$&#123;arr[$b]&#125;</span></div><div class="line">        arr[<span class="variable">$b</span>]=<span class="variable">$tmp</span></div><div class="line"><span class="keyword">done</span></div><div class="line"><span class="built_in">echo</span> <span class="variable">$&#123;#arr[@]&#125;</span></div></pre></td></tr></table></figure>
</li>
</ul>
<p>if we get this random array, we can read random lines into a new txt file , liek this:<br><figure class="highlight stylus"><table><tr><td class="code"><pre><div class="line">boundry=<span class="number">20</span></div><div class="line"><span class="keyword">for</span> <span class="selector-tag">i</span> <span class="keyword">in</span> $&#123;arr[@]:$&#123;boundry&#125;&#125;</div><div class="line">do</div><div class="line">    sed -n <span class="string">"$&#123;i&#125;p"</span> test<span class="selector-class">.txt</span> &gt;&gt; newtest<span class="selector-class">.txt</span></div><div class="line">done</div></pre></td></tr></table></figure></p>
<p>It’s simple enough! Now we have some random lines in <code>newtest.txt</code></p>
<ul>
<li><strong>Cut string</strong><br><strong>Very important part</strong>, to cut a string whatever we want is a very useful commond! And what you need is only one single cmoond <strong>cut</strong>.</li>
</ul>
<h3 id="Chapter-3-About-Mathmatic"><a href="#Chapter-3-About-Mathmatic" class="headerlink" title="Chapter 3 About Mathmatic"></a>Chapter 3 About Mathmatic</h3><p>Well, I have to say this part is a litter complicated, onething you must take in your mind is that <strong>Shell Does Not Support Decimal Calculate</strong>, though we still can find some method to approach our goal, one properly method is <strong>awk</strong>.<br>If you want to calculate 0.8x6 , you probbly can do those:</p>
<ul>
<li>$((0.8*6))</li>
<li>echo <code>expr 0.8*6</code><br>But you wont get what you want, because shell doesn’t support it. But hopefully you can do this:<figure class="highlight bash"><table><tr><td class="code"><pre><div class="line"><span class="built_in">echo</span> | awk <span class="string">'&#123;print 0.8*6&#125;'</span></div></pre></td></tr></table></figure>
</li>
</ul>
<p>you will got <code>4.2</code></p>

      
    </div>
    <footer class="article-footer">
      
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/深度学习/">深度学习</a></li></ul>

    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  
    <article id="post-Django-5-nginx-gunicorn-make-django-project-on-cloud"  class="article article-type-post" itemscope itemprop="blogPost" >
  <div id="articleInner" class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="thumb" itemprop="name">
      <a class="article-title" href="/2017/02/01/Django-5-nginx-gunicorn-make-django-project-on-cloud/">Django 5 nginx gunicorn以及django的三兄弟</a>
    </h1>
  

      </header>
    
    <div class="article-meta">
      
	<a href="/2017/02/01/Django-5-nginx-gunicorn-make-django-project-on-cloud/" class="article-date">
	  <time datetime="2017-02-01T06:14:42.000Z" itemprop="datePublished">2017-02-01</time>
	</a>

      
      
    </div>
    <div class="article-entry" itemprop="articleBody">
      
        <blockquote>
<p> 本文将介绍使用nginx和gunicorn搭建我们的django服务器，直接把应用上云！</p>
</blockquote>
<h3 id="废话不多说，开车前系紧安全带"><a href="#废话不多说，开车前系紧安全带" class="headerlink" title="废话不多说，开车前系紧安全带"></a>废话不多说，开车前系紧安全带</h3><p>首先还是啰嗦一句把，在选择一个web容器的时候我们要选择一对好兄弟，很显然，nginx的大名世人皆知，当然我之前一只听说的是apache，不过apache和java可能搭配的更多，nginx呢和django可以说是一对搭档很好的兄弟，nginx在处理静态请求方面的性能很屌，那么问题来了，动态处理是用uwsgi呢还是gunicorn呢，我选择了gunicorn，为什么呢？因为这个名字听起像个gay。既然是gay了那应该可以和django好好的搞基..</p>
<h3 id="安装nginx"><a href="#安装nginx" class="headerlink" title="安装nginx"></a>安装nginx</h3><p>好了，直接安装nginx把，这个nginx不像其它容器庞然大物，显得很小，ubuntu下直接：<br><figure class="highlight cmake"><table><tr><td class="code"><pre><div class="line">sudo apt <span class="keyword">install</span> nginx</div></pre></td></tr></table></figure></p>
<p>启动nginx服务器<br><figure class="highlight crmsh"><table><tr><td class="code"><pre><div class="line">sudo /etc/init.d/nginx <span class="literal">start</span></div><div class="line"><span class="comment"># or this command</span></div><div class="line">sudo service nginx <span class="literal">start</span></div></pre></td></tr></table></figure></p>
<p>请注意，nginx的配置文件是在这个目录里面<br><figure class="highlight awk"><table><tr><td class="code"><pre><div class="line">cd <span class="regexp">/etc/</span>nginx</div></pre></td></tr></table></figure></p>
<p>如果是Mac，则默认的nginx安装目录应该是：<br><figure class="highlight awk"><table><tr><td class="code"><pre><div class="line"><span class="regexp">/usr/</span>local<span class="regexp">/opt/</span>nginx</div></pre></td></tr></table></figure></p>
<p>要启动nginx，这也即可：<br><figure class="highlight ebnf"><table><tr><td class="code"><pre><div class="line"><span class="attribute">sudo nginx</span></div></pre></td></tr></table></figure></p>
<p>即可。<br>Mac下的nginx，配置文件目录在这里：<br><figure class="highlight awk"><table><tr><td class="code"><pre><div class="line"><span class="regexp">/usr/</span>local<span class="regexp">/etc/</span>nginx</div></pre></td></tr></table></figure></p>
<p><strong>无论是ubuntu还是Mac，nginx的配置都在 ／etc/nginx 下面，只是ubuntu直接在这下面，Mac放到了/usr/local下面</strong></p>
<blockquote>
<p>TIPS: nginx在ubuntu下默认监听的是80端口，而在mac下监听的是8080端口，因此你在ubuntu下测试nginx的欢迎页面时，可能只需要输入localhost即可，但是在mac下你必须要加上8080端口号，注意80是系统默认的监听端口，如果你要修改ubuntu下的监听端口号，比如改成8080，那么你就需要修改<code>/etc/nginx/sites-available</code>下的default文件，不过事先还是先备份一下原来的那个。</p>
</blockquote>
<p>最后插播一个东西，vim有时候你没有sudo打开需要权限的文件，改完了之后才发现要权限，然后退不出来，退出来了改完的文件就没有了，相当的蛋疼，这个时候你就需要使用这条命令：<br><figure class="highlight erlang-repl"><table><tr><td class="code"><pre><div class="line">:w !sudo tee <span class="comment">%</span></div></pre></td></tr></table></figure></p>
<p>不过要注意空格不能少，而且sudo要紧跟在感叹号后面，就这也就可以保存了。<br>最后补充一句，ngxin在Mac下和ubuntu下配置还是略有不通，ubuntu在<code>／etc/nginx/sites-available/</code>文件夹下有单独的配置文件来配置监听端口，而mac下是直接集成到了<code>/usr/local/etc/nginx</code>下的<code>nginx.cnf</code>中。</p>
<h3 id="配置一下gunicore"><a href="#配置一下gunicore" class="headerlink" title="配置一下gunicore"></a>配置一下gunicore</h3><p>首先在运行gunicore之前我们要配置一下django工程下的静态文件的路径，也就是<code>STATIC_URL</code> and <code>STATIC_ROOT</code> 这俩个变量，直接在setting.py下面设置：<br><figure class="highlight ini"><table><tr><td class="code"><pre><div class="line"><span class="attr">STATIC_ROOT</span> = os.path.join(BASE_DIR, <span class="string">'static'</span>)</div><div class="line"><span class="attr">STATIC_URL</span> = <span class="string">'/static/'</span></div></pre></td></tr></table></figure></p>
<p>然后还有一件事情，在工程中运行：<br><figure class="highlight stylus"><table><tr><td class="code"><pre><div class="line">python3 manage<span class="selector-class">.py</span> collectstatic</div></pre></td></tr></table></figure></p>
<p>这个命令会在工程根目录下生成一个static目录，并把所有的静态文件放在这下面，不过说实话如果你的django工程是一个移动app的服务器而不是网页的话，这个可能没有多大的作用，如果是网页这就直接影响到你网页的css等文件的正确加载了，一定不要忘记这个步骤。</p>
<p>这次我们来测试一下gunicore对我们django的支持怎么样，其实说白了，gunicore就是代替django原生的那个小服务器的作用。但是实际生成中肯定不能用那个小服务器，还是让更加专业的gunicore来把。<br>运行：<br><figure class="highlight css"><table><tr><td class="code"><pre><div class="line"><span class="selector-tag">gunicore</span> <span class="selector-tag">--bind</span> 0<span class="selector-class">.0</span><span class="selector-class">.0</span><span class="selector-class">.0</span><span class="selector-pseudo">:8000</span> <span class="selector-tag">yourdjangoprojectc</span><span class="selector-class">.wsgi</span><span class="selector-pseudo">:application</span></div></pre></td></tr></table></figure></p>
<p>这个命令就和<code>python3 manage.py runserver</code>是一样的。</p>
<p>OK！准确的说你已经完成了django的上线准备！<strong>nginx准备就绪，gunicore准备就绪！</strong></p>
<h3 id="Django大兄弟，上天吧"><a href="#Django大兄弟，上天吧" class="headerlink" title="Django大兄弟，上天吧"></a>Django大兄弟，上天吧</h3><p>这个教程就到这里吧，到现在才发现搭建nginx和gunicorn并没有那么简单，为此我会单独开一个post了记录这个过程。除此之外呢，基本上下个过程就是你想要的啦，保证可以学会nginx和python web环境搭建。</p>

      
    </div>
    <footer class="article-footer">
      
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Django/">Django</a></li></ul>

    </footer>
  </div>
  
</article>

<!-- Table of Contents -->

  


  <nav id="page-nav">
    
    <a class="extend prev" rel="prev" href="/page/4/">&laquo; 上一页</a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/3/">3</a><a class="page-number" href="/page/4/">4</a><span class="page-number current">5</span><a class="page-number" href="/page/6/">6</a><a class="page-number" href="/page/7/">7</a><a class="extend next" rel="next" href="/page/6/">下一页 &raquo;</a>
  </nav>

</section>
        
      </div>
      
        <div align="center" style="margin-top: 30px;"><hr class="hr" style="margin:0px; height:3px;"></div>
      
      <footer id="footer">
  

  <div class="container">
      	<div class="row">
	      <p> Powered by <a href="http://www.luoli-luoli.com/" target="_blank">萝莉萝莉</a> and <a href="http://www.luoli-luoli.com/sia" target="_blank">Sia</a> </p>
	      <p id="copyRightEn">Copyright &copy; 2017 - 2018 Jin Tian All Rights Reserved.</p>
	      
	      
    		<p class="busuanzi_uv">
				访客数 : <span id="busuanzi_value_site_uv"></span> |  
				访问量 : <span id="busuanzi_value_site_pv"></span>
		    </p>
  		   
		</div>

		
  </div>
</footer>


<!-- min height -->

<script>
    var wrapdiv = document.getElementById("wrap");
    var contentdiv = document.getElementById("content");
    var allheader = document.getElementById("allheader");

    wrapdiv.style.minHeight = document.body.offsetHeight + "px";
    if (allheader != null) {
      contentdiv.style.minHeight = document.body.offsetHeight - allheader.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    } else {
      contentdiv.style.minHeight = document.body.offsetHeight - document.getElementById("footer").offsetHeight + "px";
    }
</script>
    </div>
    <!-- <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/categories" class="mobile-nav-link">Categories</a>
  
    <a href="/tags" class="mobile-nav-link">Tags</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
    <a href="http://luoli-luoli.com/chat" class="mobile-nav-link">Chat</a>
  
</nav> -->
    

<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css">
  <script src="/fancybox/jquery.fancybox.pack.js"></script>


<script src="/js/scripts.js"></script>


  <script src="/js/home.js"></script>










	<div style="display: none;">
    <script src="https://s95.cnzz.com/z_stat.php?id=1260716016&web_id=1260716016" language="JavaScript"></script>
  </div>



	<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js">
	</script>






  </div>

  <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h2 class="modal-title" id="myModalLabel">设置</h2>
      </div>
      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">


      <div class="modal-body">
          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" onclick="javascript:setFontSize();" aria-expanded="true" aria-controls="collapseOne">
              正文字号大小
            </a>
          </div>
          <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne">
          <div class="panel-body">
            您已调整页面字体大小
          </div>
        </div>
      


          <div style="margin:6px;">
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" onclick="javascript:setBackground();" aria-expanded="true" aria-controls="collapseTwo">
              夜间护眼模式
            </a>
        </div>
          <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
          <div class="panel-body">
            夜间模式已经开启，再次单击按钮即可关闭 
          </div>
        </div>

        <div>
            <a data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="true" aria-controls="collapseThree">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;关 于&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
        </div>
         <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
          <div class="panel-body">
            Jin Tian
          </div>
          <div class="panel-body">
            Copyright © 2018 Jintian All Rights Reserved.
          </div>
        </div>
      </div>


      <hr style="margin-top:0px; margin-bottom:0px; width:80%; border-top: 1px solid #000;">
      <hr style="margin-top:2px; margin-bottom:0px; width:80%; border-top: 3px solid #000;">
      <div class="modal-footer">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
      </div>
    </div>
  </div>
</div>
  
  <a id="rocket" href="#top" class=""></a>
  <script type="text/javascript" src="/js/totop.js?v=1.0.0" async=""></script>
  
</body>
</html>